<?php
/*
 * This file is part of SoftSite.
 *
 * (c) 2012 Steve Tredinnick
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

/**
 *
 *
 * @package softsite
 * @author  Steve Tredinnick <steve.tredinnick@gmail.com>
 */



namespace Classes;

DEFINE('FATAL',"FATAL");
DEFINE('WARNING',"WARNING");
DEFINE('ERROR',"ERROR");



class Error extends BaseView
{
    private $debug = DEBUG_MODE;

    public function __construct()
    {
        parent::__construct("","");
    }

    public function ThrowError($errorType, $errorString, $errorFile, $errorLine)
    {

        $this->view->assign('error_type',$errorType);
        $this->view->assign('error_string',$errorString);
        $this->view->assign('error_file',$errorFile);
        $this->view->assign('error_line',$errorLine);
        $this->view->assign('trace',array_reverse(debug_backtrace()));

        switch ($errorType)
        {
            case FATAL:
                switch ($this->debug)
                {
                    case 0:
                        echo 'Sadly an error has occured!';
                        exit;
                    case 1:
                        $this->view->display("error/fatal.tpl");
                        exit;
                }
                break;
            case ERROR:
                $this->view->display("error/error.tpl");
                break;
            case WARNING:
                $this->view->display("error/warning.tpl");
                break;
        }
    }

    function flatten($array, $prefix = '')
    {
        $result = array();
        foreach($array as $key=>$value)
        {
            if($value == "Smarty")
            {

            }
            else
            {
                if(is_array($value))
                {
                    $result = $result + $this->flatten($value, $prefix . $key . '.');
                }
                else {
                    $result[$prefix . $key] = $value;
                }
            }
        }
        return $result;
    }
}
